Component({

	properties: {

	},
	data: {
		index: 0,
		indexs: 0,
		array: ['8：00-9：00', '9：00-10：00', '10：00-11：00', '11：00-12：00', '13：00-14：00', '14：00-15：00', '15：00-16：00',
			'16：00-17：00', '17：00-18：00'
		],
		objectArray: [{
				id: 0,
				name: '8：00-9：00'
			},
			{
				id: 1,
				name: '9：00-10：00'
			},
			{
				id: 2,
				name: '10：00-11：00 '
			},
			{
				id: 3,
				name: '11：00-12：00'
			},
			{
				id: 4,
				name: '13：00-14：00'
			},
			{
				id: 5,
				name: '14：00-15：00'
			},
			{
				id: 6,
				name: '15：00-16：00'
			},
			{
				id: 7,
				name: '16：00-17：00'
			},
			{
				id: 8,
				name: '17：00-18：00'
			}
		],
		date: '',
		datePickerValue: ['', '', ''],
		datePickerIsShow: false,
	},
	methods: {
		onShareAppMessage: function() {
			return {
				title: '南通复大预约平台',
				path: '/pages/dsorders/dsorders',
				success: function(res) {}
			}
		},
		bindPickerChange: function(e) {
			console.log('picker发送选择改变，携带值为' + this.data.array[e.detail.value])
			this.setData({
				index: e.detail.value
			})
			console.log(this.data.array[e.detail.value])
		},
		showDatePicker: function(e) {
			this.setData({
				datePickerIsShow: true,
			});
		},

		datePickerOnSureClick: function(e) {
			this.setData({
				date: `${e.detail.value[0]}-${e.detail.value[1]}-${e.detail.value[2]}`,
				datePickerValue: e.detail.value,
				datePickerIsShow: false,
			});
		},

		datePickerOnCancelClick: function(event) {
			this.setData({
				datePickerIsShow: false,
			});
		},
		formSubmit: function(e) {
			var that = this;
			var time = e.detail.value.date + ";" + this.data.array[this.data.index];
			var times = this.data.array[this.data.index];
			var date=e.detail.value.date;
			var num = date.replace(/[^0-9]/ig, "");
			var nums=parseInt(Math.random()*999);
			var yyh=num+nums;
			var name = e.detail.value.name;
			var names= name.substr(0,1)+ new Array(name.length).join('*');
			var wenti ="预约号："+yyh;
	
			if (e.detail.value.name == "") {
				wx.showToast({
					title: '姓名不能为空',
					icon: 'none',
					duration: 2000,
					mask: true
				})
				return false;
			}
			if (e.detail.value.tell == "") {
				wx.showToast({
					title: '电话不能为空',
					icon: 'none',
					duration: 2000,
					mask: true
				})
				return false;
			}
			var phone = e.detail.value.tell
			if (!(/^1[3456789]\d{9}$/.test(phone))) {
				wx.showToast({
					title: '请正确填写您的手机号码！',
					icon: 'none',
					duration: 1500
				})
				return false;
			}
			if (e.detail.value.date == "") {
				wx.showToast({
					title: '预约日期不能为空',
					icon: 'none',
					duration: 2000,
					mask: true
				})
				return false;
			}
			var click = "微信小程序南通复大预约挂号平台"
			wx.requestSubscribeMessage({
				tmplIds: ['JrWDqVpuO_OsIlFymh-YoDE9AJ2skDVmsyvjNeSpWHA'],
				success(res) {
					console.log(res)
					var click = "微信小程序南通复大预约挂号平台-电商皮杂"
					var formId = e.detail.formId;
					wx.login({
						success: res => {
							var code = res.code;
							var b = 'https://nt.jgyljt.com/jgswt/sendTemplate.php';
							wx.request({
								url: b,
								method: "post",
								header: {
									'content-type': 'application/x-www-form-urlencoded'
								},
								data: {
									name: e.detail.value.name,
									tel: e.detail.value.tell,
									date: e.detail.value.date,
									time: times,
									yuyue_num: yyh,
									templateid: "JrWDqVpuO_OsIlFymh-YoDE9AJ2skDVmsyvjNeSpWHA",
									code: code
								},
								success: function(res) {
									wx.showToast({
										title: '提交成功',
										icon: 'none',
										duration: 2000
									})
									console.log(res)
									wx.navigateTo({
										url: '/pages/dsjstss/dsjstss?name=' + names + '&tel=' + e.detail.value.tell + '&date=' + e.detail.value
											.date + '&time=' + times + '&yyh=' + yyh + '&click=' + click,
									})
								},
								fail(res) {
									wx.showToast({
										title: '提交失败',
										icon: 'none',
										duration: 2000
									})
									console.log(res)
								}
							});
							wx.request({
								url: 'https://nt.jgyljt.com/jgswt/wxds.php',
								data: {
									name: e.detail.value.name,
									tel: e.detail.value.tell,
									time: time,
									wenti: wenti,
									click: click
								},
								method: 'GET',
								success: function(res) {
								},
								fail: function() {
								},
							})
						},
					});

				}
			})
		},
		calling: function() {
			wx.makePhoneCall({
				phoneNumber: '13814647621',
				success: function() {
					console.log("拨打电话成功！")
				},
				fail: function() {
					console.log("拨打电话失败！")
				}
			})
		},
	}
})
